<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="https://css.ssl.q1.com/jquery/jquery-1.11.1.min.js?v=20170506" type="text/javascript"></script>
    <style type="text/css">
        *{padding:0;margin:0;}
    </style>
</head>
<body>
<div>输入分享地址：<input type="text" id="txt"/><input type="button" value="播放" id="play"/></div>
<iframe id="myif" width="560" height="315" src="" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

<script type="text/javascript">
    $("#play").click(function(){
        var videoKey=GetUrlRelativePath($("#txt").val());
        $("#myif").attr("src","https://www.youtube.com/embed"+videoKey+"?rel=0&autoplay=1");
    });
    function GetUrlRelativePath(txt)
    {
        var url = txt;
        var arrUrl = url.split("//");

        var start = arrUrl[1].indexOf("/");
        var relUrl = arrUrl[1].substring(start);//stop省略，截取从start开始到结尾的所有字符

        if(relUrl.indexOf("?") != -1){
            relUrl = relUrl.split("?")[0];
        }
        return relUrl;
    }
</script>

<!--<iframe width="560" height="315" src="https://www.youtube.com/embed/zXEUZtLckWg?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>-->
</body>
</html>